package quickstart;

import cn.dai.util.C3p0Utils;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.junit.Test;

import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author ArkD42
 * @file Jdbc
 * @create 2020 - 04 - 24 - 17:49
 */
public class C3p0Test {

    @Test
    public void dataSourceByC3p0() throws PropertyVetoException, SQLException {
        // 获取池对象
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        // 配置连接信息
        dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai");
        dataSource.setUser("root");
        dataSource.setPassword("123456");
        //设置初始的连接数
        dataSource.setInitialPoolSize(10);
        //获取连接
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
    }

    @Test
    public void dataSourceByC3p03() throws SQLException {
        Connection connection = C3p0Utils.getConnection();
        System.out.println(connection);
        connection.close();
    }

}
